package com.activenetwork.smlite.testcase.other;

import java.io.IOException;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import com.activenetwork.custom.uielement.decorate.IdentifierFactory;
import com.activenetwork.schema.testcase.events.createevents.basics.basics004.Basics004DataType;
import com.activenetwork.smlite.testcase.BaseCase;
import com.activenetwork.smlite.testcase.events.createEvents.basics.Basics004;
import com.activenetwork.util.EnvContext;
import com.activenetwork.util.grid.SortableGrid;
import com.activenetwork.util.grid.gson.GridFactory;
import com.activenetwork.util.jaxb.ScriptDataBindHelper;
import com.activenetwork.util.verification.gson.FailureAssertion;
import com.activenetwork.util.verification.gson.FailurePoint;

public class TestSurefireTest3 extends BaseCase {
	
	static final Logger logger = LoggerFactory.getLogger(TestSurefireTest3.class);
	private Basics004DataType data;
	
	@BeforeClass(alwaysRun = true)
	public void dataSetup() {
		try{
			ScriptDataBindHelper helper = new ScriptDataBindHelper(Basics004.class);
			data = helper.bind(Basics004DataType.class);
		}catch(IOException e){
			throw new RuntimeException("Unable to bind the script data for " + this.getClass().getName());
		}
	}
	
	@Test
	public void test3action(){
		logger.info("Read env data: " + env.getTestEnvironment().getMainSite().getUrl());
		logger.info("Read json data: " + IdentifierFactory.createBy("EventsHomeView", "searchEventInput").toString());
		logger.info("Read script xml data: " + data.getEvent().getBasic().getTitle());
		SortableGrid grid = GridFactory.getGrid("EventsHomeView", "SearchEventGrid");
		if(grid != null){
			logger.info("Grid ok");
		}
		
		logger.info(TestSurefireTest3.class.getName() + " - start");
		WebDriver driver = EnvContext.webDriverTL.get();
		
		driver.get("http://ip.chinaz.com/");
		WebElement input = driver.findElement(By.cssSelector("input#address"));
		WebElement search = driver.findElement(By.cssSelector("input#submit1"));
		input.clear();
		input.sendKeys("203.208.47.3");
		search.click();
		
		
		String result = driver.findElement(By.cssSelector("span#status strong.red")).getText();
		logger.info(result);
		
		logger.info(TestSurefireTest3.class.getName() + " - end");
		
		EnvContext.failurePointTL.get().add(new FailurePoint(
				TestSurefireTest3.class.getName(), 
				"test3action failed", 
				"test3action failed desc"));
		FailureAssertion.pop(TestSurefireTest3.class);
	}

}
